// ---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "BaseUpdateForm.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "BaseDialogForm"
#pragma link "cxGraphics"
#pragma link "cxLocalization"
#pragma link "cxButtons"
#pragma link "cxLookAndFeelPainters"
#pragma link "cxLookAndFeels"
#pragma link "dxSkinBlack"
#pragma link "dxSkinBlue"
#pragma link "dxSkinBlueprint"
#pragma link "dxSkinCaramel"
#pragma link "dxSkinCoffee"
#pragma link "dxSkinDarkRoom"
#pragma link "dxSkinDarkSide"
#pragma link "dxSkinDevExpressDarkStyle"
#pragma link "dxSkinDevExpressStyle"
#pragma link "dxSkinFoggy"
#pragma link "dxSkinGlassOceans"
#pragma link "dxSkinHighContrast"
#pragma link "dxSkiniMaginary"
#pragma link "dxSkinLilian"
#pragma link "dxSkinLiquidSky"
#pragma link "dxSkinLondonLiquidSky"
#pragma link "dxSkinMcSkin"
#pragma link "dxSkinMoneyTwins"
#pragma link "dxSkinOffice2007Black"
#pragma link "dxSkinOffice2007Blue"
#pragma link "dxSkinOffice2007Green"
#pragma link "dxSkinOffice2007Pink"
#pragma link "dxSkinOffice2007Silver"
#pragma link "dxSkinOffice2010Black"
#pragma link "dxSkinOffice2010Blue"
#pragma link "dxSkinOffice2010Silver"
#pragma link "dxSkinPumpkin"
#pragma link "dxSkinsCore"
#pragma link "dxSkinsDefaultPainters"
#pragma link "dxSkinSeven"
#pragma link "dxSkinSevenClassic"
#pragma link "dxSkinSharp"
#pragma link "dxSkinSharpPlus"
#pragma link "dxSkinSilver"
#pragma link "dxSkinSpringTime"
#pragma link "dxSkinStardust"
#pragma link "dxSkinSummer2008"
#pragma link "dxSkinTheAsphaltWorld"
#pragma link "dxSkinValentine"
#pragma link "dxSkinVS2010"
#pragma link "dxSkinWhiteprint"
#pragma link "dxSkinXmas2008Blue"
#pragma link "cxGrid"
#pragma link "cxGridBandedTableView"
#pragma link "cxGridCustomTableView"
#pragma link "cxGridCustomView"
#pragma link "cxGridDBBandedTableView"
#pragma link "cxGridLevel"
#pragma link "cxGridTableView"
#pragma resource "*.dfm"
TUBaseUpdateForm *UBaseUpdateForm;

// ---------------------------------------------------------------------------
__fastcall TUBaseUpdateForm::TUBaseUpdateForm(TComponent* Owner)
: TUBaseDialogForm(Owner) {
	ViewConfig = "";
}

// ---------------------------------------------------------------------------
void __fastcall TUBaseUpdateForm::CreateComponent() {
	if (ViewConfig == "") {
		if (EditGridIndex == FirstGridIndex)
			TUBaseDialogForm::BuildView(ModuleInfo.Conf, "//Grid/Update");
		else
			TUBaseDialogForm::BuildView(ModuleInfo.Conf,
			"//Grid[last()]/Update");
	}
	else
		TUBaseDialogForm::BuildView(ViewConfig);
}

// ---------------------------------------------------------------------------
void __fastcall TUBaseUpdateForm::CancelButtonClick(TObject *Sender) {
	this->Close();
}

// ---------------------------------------------------------------------------

void __fastcall TUBaseUpdateForm::PreviousButtonClick(TObject *Sender) {
	if (TempCaption != NULL)
		this->Caption = TempCaption;
	TableView->DataController->Controller->GoToPrev(true);
	EditRecordIndex = TableView->DataController->FocusedRecordIndex;
	CheckButtonStatus();
	ResetValue();
}
// ---------------------------------------------------------------------------

void __fastcall TUBaseUpdateForm::NextButtonClick(TObject *Sender) {
	if (TempCaption != NULL)
		this->Caption = TempCaption;
	TableView->DataController->Controller->GoToNext(true);
	EditRecordIndex = TableView->DataController->FocusedRecordIndex;
	CheckButtonStatus();
	ResetValue();
}

// ---------------------------------------------------------------------------
void __fastcall TUBaseUpdateForm::ResetValue() {
	map<String, String>ValueMap;
	TUBaseGridForm *parent = (TUBaseGridForm*)ParentForm;
	ValueMap = parent->GetTableViewRecordData(TableView);
	TUBaseDialogForm::ResetValue(&ValueMap);
}

// ---------------------------------------------------------------------------
void __fastcall TUBaseUpdateForm::AfterFormShow() {
	CheckButtonStatus();
}

// ---------------------------------------------------------------------------
void __fastcall TUBaseUpdateForm::CheckButtonStatus() {
	this->NextButton->Enabled = true;
	this->PreviousButton->Enabled = true;

	if (TableView->DataController->IsEOF()) {
		this->NextButton->Enabled = false;
	}

	if (TableView->DataController->IsBOF()) {
		this->PreviousButton->Enabled = false;
	}
}
// ---------------------------------------------------------------------------
